package com.peoplesay;

import java.util.HashMap;
import java.util.Random;

import com.google.ads.AdRequest;
import com.google.ads.AdView;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TableLayout;

public abstract class PeopleSayAbstractActivity extends Activity {
	protected Context myContext;
	protected Resources myResource;
	protected Random rnd = new Random();
	protected MediaPlayer player;
	protected OnClickListener myClickListener;

	protected TableLayout mainLayoutView;
	protected int gameSetting;

	protected String[] category = {"Girls to Gays", "Single Girls", "Black Girls",
			"Spanish Girls", "Asian Dads", "Asian Moms", "New Yorkers",
			"Nobody"};
	protected int[] categoryFiles = { 53, 32, 44, 52, 48, 64, 64, 34};
	protected String[] filePrefix = {"girltogaysay", "singlegirlsay",
			"blackgirlssay", "spanishgirlssay", "asiandadsay", "asianmomsay",
			"newyorksay", "nobodysay", };
	protected int[] categoryDrawable = { R.drawable.girltogay,
			R.drawable.singlegirl, R.drawable.blackgirl,
			R.drawable.spanishgirl, R.drawable.asiandad, R.drawable.asianmom,
			R.drawable.newyork, R.drawable.nobody};

	protected int[] buttons = {R.id.btn_girltogay, R.id.btn_singlegirl,
			R.id.btn_blackgirl, R.id.btn_spanishgirl, R.id.btn_asiandad,
			R.id.btn_asianmom, R.id.btn_newyork, R.id.btn_nobody};

	protected HashMap<Integer, Integer> buttonMap;
	protected HashMap<Integer, String> settingsMap;
	protected AdView adView;

	protected int categoryCount = category.length;
	protected int[][] soundFiles = new int[categoryCount][];

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		myContext = getApplicationContext();
		myResource = myContext.getResources();

		initalizeView();
		initalizeSoundFiles();
		initalizeListeners();

		adView = (AdView) findViewById(R.id.adView);
		adView.loadAd(new AdRequest());

		settingsMap = new HashMap<Integer, String>();
		settingsMap.put(0, "Easy");
		settingsMap.put(1, "Medium");
		settingsMap.put(2, "Hard");
		gameSetting = 0;

		start();

	}

	protected abstract void initalizeListeners();

	protected abstract void initalizeView();

	protected abstract void start();

	private void initalizeSoundFiles() {

		String resName;
		for (int i = 0; i < categoryCount; i++) {
			soundFiles[i] = new int[categoryFiles[i]];
			for (int j = 0; j < categoryFiles[i]; j++) {
				resName = filePrefix[i] + Integer.toString(j + 1);
				soundFiles[i][j] = myResource.getIdentifier(resName, "raw",
						"com.peoplesay");
			}
		}
	}


	@Override
	public void onDestroy() {
		adView.destroy();
		super.onDestroy();
	}
}
